//
//  TCTakePhotoCell.m
//  陶瓷
//
//  Created by 王戈 on 15/8/14.
//  Copyright (c) 2015年 王戈. All rights reserved.
//

#import "TCTakePhotoCell.h"

@interface TCTakePhotoCell ()


@end

@implementation TCTakePhotoCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *ID = @"TCTakePhotoCell";
    TCTakePhotoCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[TCTakePhotoCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.photoBtn];
    }
    return self;
}

- (UIButton *)photoBtn {
    if (_photoBtn == nil) {
        _photoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_photoBtn setBackgroundImage:[UIImage imageNamed:@"uploadimg"] forState:UIControlStateNormal];
        [_photoBtn addTarget:self action:@selector(takePhoto:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _photoBtn;
}

- (void)takePhoto:(UIButton *)sender {
    if (self.photoBLock) {
        _photoBLock(sender);
    }
}

- (void)takePhotoWithBLock:(takePhtoBlock)photoBLock {
    _photoBLock = photoBLock;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _photoBtn.width = self.height+30;
    _photoBtn.height = self.height-10;
    _photoBtn.x = kDefaultWindowWidth/2 - _photoBtn.width/2;
    _photoBtn.y = 10;
}

@end
